# conding = utf-8
from selenium.webdriver import ActionChains, Keys

from pages.page import Page
from pages.lyz.pycache.purchase import left_menu_sys, left_menu, find_send, find_expected, find_btn, btn_unfold, \
    member, member_options, depot, depot_options

import time


class PurchasePages(Page):

    def open_sales_order(self):
        '''
        打开管理员UI，如果已经打开则不会执行单击动作
        :return:
        '''
        if self.display(left_menu) is False:  # 如果是隐藏状态则单击
            self.click(left_menu_sys)
        self.click(left_menu)

    def btn_unfold(self):
        self.click(btn_unfold)

    def find_send(self, value):
        self.send_keys(find_send, value)
        time.sleep(1)

    def find_btn(self):
        self.click(find_btn)
        time.sleep(1)

    def member(self):
        self.click(member)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.UP)
        actions.send_keys(Keys.UP)
        time.sleep(1)
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def depot(self):
        self.click(depot)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.UP)
        actions.send_keys(Keys.UP)
        time.sleep(1)
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def search_result_text(self, value):
        '''
        根据输入的商品编号，获取查找结果
        :param search: 商品编号，用于判断返回哪个结果
        :return: 返回相应的查找结果文本
        '''
        if value == "1014":
            return self.text(find_expected)  # 如果搜索商品编号是1016，返回find_expected
